<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        .customization_toolBar {
            border: none;
        }

        .customization_toolBar .toolBar {
            border: none;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            height: 20px;
            margin: 15px 0px 0px 0px;
        }

        .customization_toolBar .toolBar .left_tool_div {
            flex-basis: 70%;
            height: 100%;
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .left_tool_div > * + * {
            margin-left: 10px;
        }

        .customization_toolBar .toolBar .right_tool_div {
            flex-basis: 30%;
            height: 100%;
            display: flex;
            flex-direction: row;
            justify-content: flex-end;
            align-items: center
        }

        .right_tool_div > * + * {
            margin-left: 10px;
        }

        .text-show-btn {
            border: none;
            font-size: 14px;
            color: #666666;
        }

        .text-show-btn:hover {
            color: #666666;
        }

        #dataPreviewTable {
            width: 100%;
        }

        .dropDown {
            padding: 0 0;
            background-color: #ffffff
        }

        .dropDownBtn {
            padding: 0 0 !important;
        }

        .dropDownBtn .layui-nav-more {
            display: none;
        }

        .dropDown dl {
            width: 100px;
        }

        .dropDownBtn .layui-nav-bar {
            display: none !important;
        }

        .dropDown .layui-nav-bar {
            display: none !important;
        }

        .table-toolbar-fixed {
            position: fixed;
            top: 0;
            z-index: 999;
            height: 40px;
            background-color: #ffffff
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" lay-filter="searchForm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">收货人姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="consigneeName" autocomplete="off" class="layui-input"
                                       placeholder="请输入收货人姓名">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="consigneePhone" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="orderId" autocomplete="off" class="layui-input"
                                       placeholder="请输入详细的订单编号">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">物流单号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="courierNumber" autocomplete="off" class="layui-input"
                                       placeholder="请输入详细的物流单号">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsName" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">区域服务商</label>
                            <div class="layui-input-inline">
                                <input type="text" name="providersName" autocomplete="off" class="layui-input"
                                       placeholder="请填写，如88888888">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">交易时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="dateRange" id="dateRange" class="layui-input"
                                       placeholder="请选择时间区间">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <fieldset class="customization_toolBar">
            <div class="toolBar">
                <div class="left_tool_div">
                    <div><label id="dateRangeStr" style="font-weight: bold;font-size: 16px"></label></div>
                    <div>
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="stateSearch('已付款')">
                            待发货<label id="PAYMENT" style="color:#ff0004;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="stateSearch('已发货')">
                            已发货<label id="SHIPPED" style="color:#ffd200;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="stateSearch('已完成')">
                            已完成<label id="COMPLETED" style="color:#00ff00;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="stateSearch('已退款')">
                            退款<label id="REFUNDED" style="color:#616161;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div>
                        <form class="layui-form">
                            <input type="checkbox" lay-skin="primary" lay-filter="showAll"
                                   title="全部">
                        </form>
                    </div>
                    <div>
                        <form class="layui-form">
                            <input type="checkbox" lay-skin="primary" lay-filter="filterTestOrder"
                                   title="过滤" checked>
                        </form>
                    </div>
                </div>
                <div class="right_tool_div">
                    <div>
                        <ul class="layui-nav dropDown">
                            <li class="layui-nav-item">
                                <a href="javascript:;" class="dropDownBtn">
                                    <button class="layui-btn layui-btn-sm layui-btn">
                                        发货
                                    </button>
                                </a>
                                <dl class="layui-nav-child">
                                    <dd><a href="javascript:;" class="dataChanges-button-click"
                                           data-value="DELIVERGOODS">发货</a></dd>
                                    <dd><a href="javascript:;" class="dataChanges-button-click"
                                           data-value="CHANGELOGISTICS">改物流</a></dd>
                                    <dd><a href="javascript:;" class="batchImport" data-value="GROUPBUY_BATCH_DELIVERY">
                                        批量发货</a>
                                    </dd>
                                    <dd><a href="javascript:;" class="dataChanges-button-click" data-value="SENDNOTIFY">
                                        发送通知</a>
                                    </dd>
                                </dl>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <ul class="layui-nav dropDown">
                            <li class="layui-nav-item">
                                <a href="javascript:;" class="dropDownBtn">
                                    <button class="layui-btn layui-btn-sm layui-btn">
                                        录入供货价
                                    </button>
                                </a>
                                <dl class="layui-nav-child">
                                    <dd><a href="javascript:;" class="dataChanges-button-click"
                                           data-value="ENTERPRICE">录入供货价</a>
                                    </dd>
                                    <dd><a href="javascript:;" class="batchImport"
                                           data-value="GROUPBUY_ENTER_SUPPLYPRICE">导入供货价</a>
                                    </dd>
                                </dl>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn single-select—btn dataChanges-button-click"
                                data-value="REFUND">
                            退款
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-danger single-select—btn data-delete-btn dataChanges-button-click"
                                data-value="SHIPPINGADDRESS">
                            改收货信息
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-warm orderExportExcel">
                            导出
                        </button>
                    </div>
                </div>
            </div>


        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../lib/SheetJS/xlsx.full.min.js" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/common/permissions.js" charset="utf-8"></script>
<script>
    let allBtnSelect;
    let orderStatus = '';
    let filterTestOrder = true;
    let importAction = 0;
    layui.use(['form', 'table', 'laydate', 'colorpicker'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            colorpicker = layui.colorpicker;

        //执行一个laydate实例
        laydate.render({
            elem: '#dateRange', //指定元素
            max: 0, // 限制最大值为当前日期
            format: 'yyyy-MM-dd', //日期格式
            type: 'date',
            range: true, //开启范围选择
        });

        // 默认时间文本
        let defDateRange = new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000).toLocaleDateString().split('/').map(function (item) {
            return item.padStart(2, '0');
        }).join('-') + " - " + new Date().toLocaleDateString().split('/').map(function (item) {
            return item.padStart(2, '0');
        }).join('-')
        setDateRangeStr(defDateRange)

        const btnRoles = {
            "entitySwitch": 'admin',
        }
        const roles = buttonPermissions(btnRoles)
        roles.then(rolesMap => {
            table.render({
                elem: '#currentTableId',
                url: '/trade/order/record/page/list',
                where: {
                    dateRange: getDateRangeJsonStr()
                },
                method: 'GET',
                contentType: 'application/x-www-form-urlencoded',
                parseData: function (res) { //res 即为原始返回的数据
                    let data = res.data;
                    // 处理数据
                    let orderStatusCount = data.orderStatusCount;
                    if (orderStatusCount) {
                        const myMap = new Map(Object.entries(orderStatusCount));
                        // 更新统计数据
                        myMap.forEach((value, key) => {
                            let id = '#' + key
                            $(id).text('(' + value + ')');
                        });
                    }
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": data.total, //解析数据长度
                        "data": data.list //解析数据列表
                    };
                },
                toolbar: false,
                cols: [[
                    {type: "checkbox", fixed: 'left'},
                    {
                        field: 'numbering', title: '序号', width: 60, align: 'center', templet: function (d) {
                            return d.LAY_INDEX; //返回序号
                        }
                    },
                    {field: 'id', title: '订单id', hide: true, sort: true, align: 'center', minWidth: 150},
                    {
                        field: 'markColor', title: '标记', sort: false, align: 'center', width: 60,
                        templet: function (d) {
                            return '<div id="color-' + d.id + '" ></div>';
                        }
                    },
                    {
                        field: 'orderStatus',
                        title: '订单状态',
                        sort: true,
                        align: 'center',
                        minWidth: 150,
                        templet: function (d) {
                            if (d.orderStatus === '已付款') {
                                return '<span style="color:#ff0000;">待发货</span>'
                            } else if (d.orderStatus === '已发货') {
                                return '<span style="color:#ffc40f;">已发货</span>'
                            } else if (d.orderStatus === '已完成') {
                                return '<span style="color:#319b62;">已完成</span>'
                            } else if (d.orderStatus === '已退款') {
                                return '<span style="color:#b1b1b1;">已退款</span>'
                            } else {
                                return '<span style="color:#ffc40f;">' + d.orderStatus + '</span>'
                            }
                        }
                    },
                    {field: 'joinTime', title: '交易时间', sort: true, align: 'center', minWidth: 200},
                    // {field: 'entity', title: '实物', sort: true, align: 'center', minWidth: 100},
                    {
                        field: 'entity',
                        title: '实物',
                        sort: true,
                        align: 'center',
                        minWidth: 100,
                        templet: function (d) {
                            if (d.entity === 'YES') {
                                return rolesMap.get('entitySwitch') ? '<input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchEntity" lay-text="是|否">' : '发'
                            } else {
                                return rolesMap.get('entitySwitch') ? '<input type="checkbox" name="open" lay-skin="switch" lay-filter="switchEntity" lay-text="是|否">' : '不发'
                            }

                        }
                    },
                    {
                        field: 'consigneeName',
                        title: '收货人',
                        sort: true,
                        align: 'center',
                        minWidth: 150,
                        templet: function (d) {
                            if (d.addressInfoChange) {
                                return '<span>' + d.consigneeName + '<label style="color: red">(改)</label>' + ' </span>'
                            } else {
                                return '<span>' + d.consigneeName + ' </span>'
                            }
                        }
                    },
                    {field: 'consigneePhoneNum', title: '手机号', sort: true, align: 'center', minWidth: 150},
                    {field: 'goodsName', title: '商品名称', sort: true, align: 'center', minWidth: 300},
                    {field: 'shippingLink', title: '发货链接', sort: true, align: 'center', minWidth: 300},
                    {field: 'goodsBrand', title: '品牌', sort: true, align: 'center', minWidth: 150},
                    {
                        field: 'goodsCategory',
                        title: '分类',
                        sort: true,
                        align: 'center',
                        minWidth: 80,
                        templet: function (d) {
                            if (d.goodsCategoryList) {
                                return d.goodsCategoryList[0]
                            }
                        }
                    },
                    {
                        field: 'goodsCategory',
                        title: '类目',
                        sort: true,
                        align: 'center',
                        minWidth: 80,
                        templet: function (d) {
                            if (d.goodsCategoryList) {
                                return d.goodsCategoryList[1] ?? ''
                            }
                        }
                    },
                    {
                        field: 'goodsCategory',
                        title: '品类',
                        sort: true,
                        align: 'center',
                        minWidth: 80,
                        templet: function (d) {
                            if (d.goodsCategoryList) {
                                return d.goodsCategoryList[2] ?? ''
                            }
                        }
                    },
                    {field: 'unitPrice', title: '玫丽价', sort: true, align: 'center', minWidth: 100},
                    {field: 'supplyPrice', title: '供货价', sort: true, align: 'center', minWidth: 100},
                    {field: 'orderId', title: '订单编号', sort: true, align: 'center', minWidth: 200},
                    {field: 'buyQuantity', title: '购买数量', sort: true, align: 'center', minWidth: 100},
                    {field: 'originalPayAmount', title: '应付总额', sort: true, align: 'center', minWidth: 100},
                    {field: 'couponAmount', title: '优惠券金额', sort: true, align: 'center', minWidth: 120},
                    {field: 'deductionAmount', title: '钱包抵扣金额', sort: true, align: 'center', minWidth: 120},
                    {field: 'payAmount', title: '实付金额', sort: true, align: 'center', minWidth: 120},
                    {field: 'realSupplyPrice', title: '实际供货价', sort: true, align: 'center', minWidth: 100},
                    {field: 'orderRemarks', title: '订单备注', sort: true, align: 'center', minWidth: 150},
                    {field: 'consigneeAddress', title: '收货地址', sort: true, align: 'center', minWidth: 300},
                    {field: 'deliveryTime', title: '发货时间', sort: true, align: 'center', minWidth: 200},
                    {field: 'courierName', title: '物流公司', align: 'center', minWidth: 100},
                    {field: 'courierNumber', title: '物流单号', align: 'center', minWidth: 130},
                    {field: 'partnerName', title: '消费者', sort: true, align: 'center', minWidth: 120},
                    {
                        field: 'initiatorName',
                        title: '代理服务商',
                        sort: true,
                        align: 'center',
                        minWidth: 120,
                        templet: function (d) {
                            if (d.onlineProvider) {
                                return '<span>' + d.onlineProvider?.nickName + '（NO.' + d.onlineProvider?.providerId + '） </span>'
                            } else {
                                return '未注册'
                            }
                        }
                    },
                    {
                        field: 'providerName',
                        title: '选址服务商',
                        sort: true,
                        align: 'center',
                        minWidth: 120,
                        templet: function (d) {
                            if (d.offlineProvider) {
                                return '<span>' + d.offlineProvider?.nickName + '（NO.' + d.offlineProvider?.providerId + '） </span>'
                            } else {
                                return '未注册'
                            }
                        }
                    },
                ]],
                limits: [50, 100, 150, 200],
                limit: 50,
                page: true,
                request: {
                    pageName: 'pageNum',
                    limitName: 'pageSize'
                },
                response: { //定义后端 json 格式，详细参见官方文档
                    statusName: 'code', //状态字段名称
                    statusCode: '200', //状态字段成功值
                    msgName: 'msg', //消息字段
                    countName: 'count', //总数字段
                    dataName: 'data' //数据字段
                },
                done: function (res, curr, count) {
                    let headertop = $(".customization_toolBar").offset().top//获取表头到文档顶部的距离
                    let toolBarWith = $(".customization_toolBar").width()
                    $(window).scroll(function () {//开始监听滚动条
                        if (headertop - $(window).scrollTop() < 0) {    //超过了
                            $(".customization_toolBar").addClass('table-toolbar-fixed').width(toolBarWith)//添加样式，固定住表头
                        } else {//没超过
                            $(".customization_toolBar").removeClass('table-toolbar-fixed')//移除样式
                        }
                    })

                    $.each(table.cache['currentTableId'], function (index, item) {
                        // 为每个颜色选择器绑定 colorpicker 事件
                        colorpicker.render({
                            elem: '#color-' + item.id,
                            color: item.markColor,
                            predefine: true, // 预定义颜色块
                            format: 'hex',
                            alpha: false, // 不显示透明度选择
                            colors: ['#fe5722', '#1e9fff', '#feb800', '#009687', '#b1b1b1'],
                            done: function (color) {
                                const requestDta = {
                                    id: item.id,
                                    markColor: color
                                }
                                $.ajax({
                                    url: '/buying/update/groupBuy/order',
                                    type: 'POST',
                                    dataType: 'json',
                                    contentType: 'application/json; charset=UTF-8',
                                    data: JSON.stringify(requestDta),
                                    success: function (data) {

                                    },
                                    error: function (e) {
                                        layer.msg(e.msg);

                                    }
                                });
                            },
                            change: function (color) {
                                return false;
                            }
                        });
                    });
                }
            });
        });


        form.on('switch(switchEntity)', function (data) {
            let rowIndex = $(data.elem).closest('tr').data('index');
            let rowData = table.cache['currentTableId'][rowIndex];
            const requestDta = {
                id: rowData.id,
                entity: 'YES'
            }
            if (data.elem.checked) {
                requestDta.entity = 'YES';
            } else {
                requestDta.entity = 'NO';
            }

            $.ajax({
                url: '/buying/update/groupBuy/order',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json; charset=UTF-8',
                data: JSON.stringify(requestDta),
                success: function (data) {

                },
                error: function (e) {
                    layer.msg(e.msg);

                }
            });
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let dataRangeStr = data.field.dateRange
            if (isNotNull(orderStatus)) {
                orderStatus = '';
            }
            if (isNotNull(dataRangeStr)) {
                setDateRangeStr(dataRangeStr)
            }
            loadingTable();
            return false;
        });


        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            let checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
            if (data.length === 1) {
                // 修改按钮启用
                $(".single-select—btn").removeClass('layui-btn-disabled')
            } else {
                $(".single-select—btn").addClass('layui-btn-disabled')
            }
        });


        form.on('checkbox(showAll)', function (data) {
            if (data.elem.checked) { //判断复选框是否选中
                $('#dateRange').val("")
                allBtnSelect = true;
                setDateRangeStr("");
            } else {
                allBtnSelect = false;
                setDateRangeStr(defDateRange)
            }
            if (isNotNull(orderStatus)) {
                orderStatus = '';
            }
            loadingTable();
        });

        // 是否过滤测试数据
        form.on('checkbox(filterTestOrder)', function (data) {
            if (data.elem.checked) { //判断复选框是否选中
                filterTestOrder = true;
            } else {
                filterTestOrder = false;
            }
            loadingTable();
        });


        // 监听批量发货按钮
        $('.batchImport').click(function () {
            let value = $(this).data('value');
            if (!isNotNull(value)) {
                layer.msg("数据异常，请重试");
                return;
            }
            let checkStatus = table.checkStatus('currentTableId');
            let formDate = form.val('searchForm');
            formDate.dateRange = getDateRangeJsonStr();
            let param = {
                batchIds: [],
                actions: value,
                batchType: 0,
                queryVO: formDate,
            }
            let dataList = checkStatus.data;
            if (dataList.length > 0) {
                let ids = [];
                dataList.forEach(function (item) {
                    ids.push(item.id)
                });
                param.batchIds = ids;
            } else {
                param.batchType = 1;
            }
            const index = layer.open({
                type: 2,
                title: value === 'GROUPBUY_BATCH_DELIVERY' ? "批量发货" : "导入供货价",
                content: '../common/import/importComponents.html',
                area: ['274px', '140px'],
                success: function (layero, index) {
                    // 获取子页面的iframe
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child传参
                    let data = {
                        module: value,
                        param: param,
                        templateName: value === 'GROUPBUY_BATCH_DELIVERY' ? '订单批量发货模板.xlsx' : '订单导入供货价模板.xlsx',
                        dataPreviewUrl: '../common/import/dataPreviewTable.html',
                        errTemplateName: value === 'GROUPBUY_BATCH_DELIVERY' ? '发货失败数据.xlsx' : '导入失败数据.xlsx',
                    }
                    iframe.childParam(data);
                },
                end: function () {
                    //关闭弹框后触发
                    reloadTable()
                }
            });
        })


        // 监听导出按钮
        $('.orderExportExcel').click(function () {
            let checkStatus = table.checkStatus('currentTableId');
            let formDate = form.val('searchForm');
            if (isNotNull(orderStatus)) {
                formDate.orderStatus = orderStatus;
            }
            formDate.dateRange = getDateRangeJsonStr();
            formDate.filterTestOrder = filterTestOrder;
            let data = {
                batchIds: [],
                batchType: 0,
                queryVO: formDate,
            }
            if (checkStatus.isAll) {
                data.batchType = 1;
            } else {
                let dataList = checkStatus.data;
                if (dataList.length > 0) {
                    let ids = [];
                    dataList.forEach(function (item) {
                        ids.push(item.id)
                    });
                    data.batchIds = ids;
                } else {
                    data.batchType = 1;
                }
            }
            downloadExcel('/trade/order/export/excel', data, '订单记录.xlsx', 'POST')
        });

        // 监听发货和该物流按钮
        $('.dataChanges-button-click').click(function () {
            let value = $(this).data('value');
            if (!isNotNull(value)) {
                layer.alert('数据异常，请重试！');
                return;
            }
            let checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
            if (data.length === 0) {
                layer.alert('至少选中一行数据');
                return;
            }
            var select_data = data[0];// 选中的
            if (value === 'DELIVERGOODS') {  // 监听发货操作
                if (select_data.orderStatus === '已完成') {
                    layer.alert('订单已完成！');
                    return;
                }
                if (select_data.orderStatus === '已发货') {
                    layer.alert('已发货，无需再处理！');
                    return;
                } else {
                    var index = layer.open({
                        title: '快递信息填写页面',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['40%', '50%'],
                        content: './express-info-config.html?recordId=' + select_data.id,
                        end: function () {
                            //关闭弹框后触发
                            reloadTable()
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                }
            } else if (value === 'CHANGELOGISTICS') {  // 监听改物流操作
                if (select_data.orderStatus === '已完成') {
                    layer.alert('订单已完成！');
                    return;
                }
                if (select_data.orderStatus == '已付款') {
                    layer.alert('只能进行改物流操作，无法进行发货操作！');
                    return;
                } else {
                    var index = layer.open({
                        title: '快递信息填写页面',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['40%', '50%'],
                        content: './express-info-config.html?recordId=' + select_data.id,
                        end: function () {
                            //关闭弹框后触发
                            reloadTable()
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                }
            } else if (value === 'SHIPPINGADDRESS') {
                var index = layer.open({
                    title: '收货地址更改',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: './shippingAddress.html?recordId=' + select_data.id,
                });
            } else if (value === 'SENDNOTIFY') {
                if (select_data.orderStatus === '已付款') {
                    layer.alert('该订单未发货，请先发货');
                    return;
                }
                if (select_data.orderStatus === '已完成') {
                    layer.alert('该订单已完成');
                    return;
                }
                let courierName = select_data.courierName;
                let courierNumber = select_data.courierNumber;
                if (!isNotNull(courierName) || !isNotNull(courierNumber)) {
                    layer.msg('物流公司或物流单号为空，不可发送通知');
                }
                // 样品发货短信通知
                const requestData = {
                    sendTo: select_data.consigneeName,
                    phoneNumber: select_data.consigneePhoneNum,
                    commodity: select_data.goodsName,
                    company: select_data.courierName,
                    numbers: select_data.courierNumber
                }
                let index = layer.alert("确定向该用户发送发货通知？", {
                    title: '提示'
                }, function () {
                    let myMsg = layer.msg("正在处理...", {
                        icon: 16,
                        time: -1
                    })
                    $.ajax({
                        type: "post",
                        url: '/notify/send/goods/delivery',
                        data: JSON.stringify(requestData),
                        dataType: 'json',
                        contentType: 'application/json; charset=UTF-8',
                        success: function (req) {
                            if (req.code === '200') {
                                layer.msg('已发送');
                                layer.close(index);
                                // 关闭弹出层
                            } else {
                                layer.msg(req.msg);
                            }

                        },
                        error: function (e) {
                            layer.msg(e.msg);
                            layer.close(myMsg);//手动关闭
                        }
                    })
                });
            } else if (value === 'ENTERPRICE') {
                var index = layer.open({
                    title: '录入供货价',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['40%', '50%'],
                    content: './enterPrice.html?id=' + select_data.id,
                    end: function () {
                        //关闭弹框后触发
                        reloadTable()
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (value === 'REFUND') {
                layer.open({
                    title: '订单退款操作',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['50%', '80%'],
                    content: './order-refund.html?id=' + select_data.id,
                });
            }
        });

        // 监听表格 行双击事件
        table.on('rowDouble(currentTableFilter)', function (obj) {
            var index = layer.open({
                title: '订单详情',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: './order-detail.html?recordId=' + obj.data.id,
                end: function () {
                    //关闭弹框后触发
                    reloadTable()
                }
            });
            $(window).on("resize", function () {
                layer.full(index);
            });

        });

    });

    /**
     * 重载表格数据
     */
    function reloadTable() {
        layui.use(['table'], function () {
            let table = layui.table;
            table.reload('currentTableId', {
                url: '/trade/order/record/page/list'
            });
        })
    }

    /**
     * 重载表格数据
     */
    function loadingTable() {
        layui.use(['form', 'table', 'jquery'], function () {
            var form = layui.form,
                table = layui.table,
                $ = layui.jquery;
            let formDate = form.val('searchForm');
            formDate.dateRange = getDateRangeJsonStr();
            formDate.orderStatus = orderStatus;
            formDate.filterTestOrder = filterTestOrder;
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: formDate
            }, 'data');
        })
    }

    function stateSearch(state) {
        orderStatus = state;
        loadingTable();
    }

    // 设置日期显示的文本内容
    function setDateRangeStr(defDateRange) {
        if (!isNotNull(defDateRange)) {
            $("#dateRangeStr").text('全部订单');
            return;
        }
        const [startDateStr, endDateStr] = defDateRange.split(' - ');
        const startDate = new Date(startDateStr);
        const endDate = new Date(endDateStr);
        // 格式化开始日期和结束日期
        const formattedStartDate = formatDate(startDate);
        const formattedEndDate = formatDate(endDate);// 组合新的日期字符串
        const newDateStr = `${formattedStartDate} - ${formattedEndDate}`;
        $("#dateRangeStr").text(newDateStr);
    }

    // 获取时间查询区间
    function getDateRangeJsonStr() {
        let dateRangeStr = $('#dateRange').val();
        if (!isNotNull(dateRangeStr)) {
            if (allBtnSelect) {
                // 代表全部被选中了
                return '{}';
            } else {
                // 默认7天内
                dateRangeStr = new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000).toLocaleDateString().split('/').map(function (item) {
                    return item.padStart(2, '0');
                }).join('-') + " - " + new Date().toLocaleDateString().split('/').map(function (item) {
                    return item.padStart(2, '0');
                }).join('-')
            }

        }
        let dataRangeList = dateRangeStr.split(` - `)
        let dataRange = {}
        if (dataRangeList.length === 2) {
            dataRange = {
                'startDate': dataRangeList[0],
                'endDate': dataRangeList[1]
            }
        }
        return JSON.stringify(dataRange)
    }

</script>

</body>
<style>
    /*去除颜色选择器的默认样式*/
    .layui-colorpicker {
        border: none !important; /* 去除边框 */
        box-shadow: none !important; /* 去除默认样式 */
    }

    .layui-colorpicker-trigger-span .layui-colorpicker-trigger-i {
        display: none !important; /* 隐藏下拉箭头 */
    }

    .layui-colorpicker-main-wrapper {
        display: none !important;
    }

    .layui-colorpicker-main-input .layui-inline {
        display: none !important;
    }

    .layui-colorpicker-main-input .layui-btn-container .layui-btn-primary {
        display: none !important;
    }

    .layui-colorpicker-main {
        width: 7% !important;
    }
</style>
</html>